
package com.cms.manage.util;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.UUID;

/**
 * <p>
 * Description: UUID生成器
 * </p>
 */
public final class UUIDGenerator {

    private UUIDGenerator() {
    }

    /**
     * 获得一个UUID
     * @return String UUID
     */
    public static String getUUID() {
        String uuidString = UUID.randomUUID().toString();
        return uuidString;
    }

    /**
     * 获得一个32位UUID
     * @return String UUID
     */
    public static String getUUID32() {
        String uuidString = UUID.randomUUID().toString().replaceAll("-", "");
        return uuidString;
    }
    /**
     * 获取没有横杆的UUID
     * @return
     * @version: v1.0.0
     */
    public static String getUUID2(){
    	return UUID.randomUUID().toString().replaceAll("-", "");
    }

    
    private static String _tempFinanceId = "";

    /**
     * 生成4位长度的字符串数字长度不足前面补零
     * @param number
     * @return
     */
    public static String formatNumber_4(int number){
    	return String.format("%04d", number);
    }
    
    /**
    * 生成5位长度的字符串数字长度不足前面补零
    * @param number
    * @return
    */
    public static String formatNumber_5(int number){
    	return String.format("%05d", number);
    }
    
    public static int parseTextNum_4(String textNum){
		return parseTextNum("0000", textNum);
    }
    
    public static int parseTextNum_5(String textNum){
    	return parseTextNum("00000", textNum);
    }
    
    /**
     * 字符串号码转换为数字号码
     * @param pattern 00000
     * @param textNum 00012
     * @return 12
     */
    public static int parseTextNum(String pattern, String textNum){
    	DecimalFormat df = new DecimalFormat(pattern);
    	try {
			return df.parse(textNum).intValue();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return 0;
    }
}
